﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CreateFloor : System.Web.UI.Page
{
    private string[] _rows = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"};

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString.ToString()))
        {
            int rows = Convert.ToInt32(Request.QueryString["rows"]);
            int seats = Convert.ToInt32(Request.QueryString["seats"]);
            CreateScreenTemplate2(rows, seats);
        }
    }

    protected void SendInfo(object sender, EventArgs e)
    {
        int rows = Convert.ToInt32(DropDownListRows.Text);
        int seats = Convert.ToInt32(DropDownListSeats.Text);
        Response.Redirect("CreateFloor.aspx?rows="+rows+"&seats="+seats+"");
    }

    protected void CreateScreenTemplate2(int rows, int seats)
    {
        int rowCounter = 1;
        int seatCounter = 1;
        int seatUnique = 100000;

        while (rowCounter <= rows)
        {
            String rowId = Convert.ToString(10000 + rowCounter);
            Panel newRow = new Panel { CssClass = "Row", ID = rowId };

            while (seatCounter <= seats)
            {
                string seatId = Convert.ToString(seatCounter + seatUnique);
                Panel seatBox = new Panel { CssClass = "SeatBox" };
                Button seat = new Button { CssClass = "Seat SeatAvailable", ID = seatId, Text = "1" };
                seat.Click += PickSeat;
                seatBox.Controls.Add(seat);
                newRow.Controls.Add(seatBox);
                seatCounter++;
            }
            seatCounter = 1;
            seatUnique += 100000;
            FloorDiv.Controls.Add(newRow);
            rowCounter++;
        }
    }

    protected void CreateScreenTemplate(object sender, EventArgs e)
    {
        int rowCounter = 1;
        int seatCounter = 1;
        int seatUnique = 100000;
        int rows = Convert.ToInt32(DropDownListRows.Text);
        int seats = Convert.ToInt32(DropDownListSeats.Text);

        while (rowCounter <= rows)
        {
            String rowId = Convert.ToString(10000 + rowCounter);
            Panel newRow = new Panel {CssClass = "Row", ID = rowId};

            while (seatCounter <= seats)
            {
                string seatId = Convert.ToString(seatCounter + seatUnique);
                Panel seatBox = new Panel {CssClass = "SeatBox"};
                Button seat = new Button {CssClass = "Seat SeatAvailable", ID = seatId, Text = "1"};
                seat.Click += PickSeat;
                seatBox.Controls.Add(seat);
                newRow.Controls.Add(seatBox);
                seatCounter++;
            }
            seatCounter = 1;
            seatUnique += 100000;
            FloorDiv.Controls.Add(newRow);
            rowCounter++;
        }
    }

    protected void CreateFloorDesigner(object sender, EventArgs e)
    {
        int counter = 1;
        foreach (string row in _rows)
        {
            Panel newRow = new Panel { CssClass = "Row" };

            while (counter < 31)
            {
                Panel seat = new Panel { CssClass = "SeatBox" };

                Button b = new Button { CssClass = "Seat SeatAvailable", ID = row + counter, Text = "1" };
                b.Click += PickSeat;

                seat.Controls.Add(b);
                newRow.Controls.Add(seat);
                counter++;
            }

            FloorDiv.Controls.Add(newRow);
            counter = 1;
        }
    }

    protected void PickSeat(object sender, EventArgs e)
    {
        Button b = (Button)sender;
        string bText = b.Text;

        if (bText.Equals("1"))
        {
            b.CssClass = "Seat SeatDisabled";
            b.Text = "0";
        }
        else
        {
            b.CssClass = "Seat SeatAvailable";
            b.Text = "1";
        }
    }
}